<?php

/**
 * This is the model class for table "{{manage}}".
 *
 * The followings are the available columns in table '{{manage}}':
 * @property integer $admin_id
 * @property string $admin_name
 * @property string $realname
 * @property integer $rankid
 * @property string $email
 * @property string $pwd
 * @property string $pwd_hash
 * @property string $phone
 * @property integer $login_state
 * @property integer $add_time
 * @property integer $last_login_time
 * @property string $last_login_ip
 * @property integer $avatar
 * @property integer $logintimes
 * @property integer $post
 * @property integer $comments
 * @property integer $pv
 */
class Manage extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{manage}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('admin_name, realname, rankid, email, pwd, pwd_hash, phone, add_time, last_login_time, last_login_ip, avatar, logintimes', 'required'),
			array('rankid, login_state, add_time, last_login_time, avatar, logintimes, post, comments, pv', 'numerical', 'integerOnly'=>true),
			array('admin_name, realname, email', 'length', 'max'=>40),
			array('pwd', 'length', 'max'=>255),
			array('pwd_hash', 'length', 'max'=>32),
			array('phone', 'length', 'max'=>20),
			array('last_login_ip', 'length', 'max'=>15),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('admin_id, admin_name, realname, rankid, email, pwd, pwd_hash, phone, login_state, add_time, last_login_time, last_login_ip, avatar, logintimes, post, comments, pv', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'admin_id' => 'Admin',
			'admin_name' => 'Admin Name',
			'realname' => 'Realname',
			'rankid' => 'Rankid',
			'email' => 'Email',
			'pwd' => 'Pwd',
			'pwd_hash' => 'Pwd Hash',
			'phone' => 'Phone',
			'login_state' => 'Login State',
			'add_time' => 'Add Time',
			'last_login_time' => 'Last Login Time',
			'last_login_ip' => 'Last Login Ip',
			'avatar' => 'Avatar',
			'logintimes' => 'Logintimes',
			'post' => 'Post',
			'comments' => 'Comments',
			'pv' => 'Pv',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('admin_id',$this->admin_id);
		$criteria->compare('admin_name',$this->admin_name,true);
		$criteria->compare('realname',$this->realname,true);
		$criteria->compare('rankid',$this->rankid);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('pwd',$this->pwd,true);
		$criteria->compare('pwd_hash',$this->pwd_hash,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('login_state',$this->login_state);
		$criteria->compare('add_time',$this->add_time);
		$criteria->compare('last_login_time',$this->last_login_time);
		$criteria->compare('last_login_ip',$this->last_login_ip,true);
		$criteria->compare('avatar',$this->avatar);
		$criteria->compare('logintimes',$this->logintimes);
		$criteria->compare('post',$this->post);
		$criteria->compare('comments',$this->comments);
		$criteria->compare('pv',$this->pv);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Manage the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
    public function findUserInfo($username){
        return $this->find('admin_name=:admin_name',array(':admin_name'=>$username));
    }
}
